1
From Structs to Abstract Data Types
AI037 Lesson 11
00:00

The journey from a struct to an Abstract Data Type (ADT) marks the transition from a "Glass Box," where every internal wire is exposed, to a "Black Box" where the interface is separated from the implementation. This shift ensures encapsulation: users interact with functions like read or combine without needing to know how revenue is calculated or stored.

1. Class Architecture

Every class defines a unique type identity. Even if two classes share identical members, C++ treats them as incompatible. Using typedef and forward declarations (e.g., class Screen;) allows us to design complex relationships while maintaining abstraction. We often use synthesized versions of constructors, like Sales_data() = default;, to maintain the convenience of built-in types ($$total = trans;$$).

The ADT "Black Box" Implementation (Private) read print add PUBLIC INTERFACE

2. Nonmember Interface Functions

Functions like read are Nonmember Class-Related Functions. They are part of the interface but not the class itself, often requiring friendship to access private data.

main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>